/**   
* 所属公司：稻普控股集团
* 项目名称：dpqc-parent-manager-date   
* 类名称：DateUtil   
* 类描述：   
* 创建人：zhangpp
* 创建时间：2017年4月5日 下午5:58:46   
* 修改人：zhangpp
* 修改时间：2017年4月5日 下午5:58:46   
* 修改备注：   
* @version V1.0     
*/ 
package com.zjdiepu.www.common.util;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

/**   
 * 所属公司：稻普控股集团
 * 项目名称：dpqc-parent-manager-date   
 * 类名称：DateUtil   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年4月5日 下午5:58:46   
 * 修改人：zhangpp
 * 修改时间：2017年4月5日 下午5:58:46   
 * 修改备注：   
 * @version V1.0     
 */
public class ZhppDateUtil {

	
	public static final int currentTimeMillis = (int) (System.currentTimeMillis() / 1000);
	
	public static final String SHORT_DATE_FORMAT = "yyyy-MM-dd";
	
	public static final String LONG_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
	
	public static final SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");

    public static final SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");

    public static final SimpleDateFormat format6 = new SimpleDateFormat("yyyy/MM/dd");

    public static final SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static final SimpleDateFormat format4 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

    public static final SimpleDateFormat format5 = new SimpleDateFormat("yyyyMMddHHmmss");
	
    
    /**
     * 判断当前日期是星期几
     * @param pTime 修要判断的时间
     * @return dayForWeek 判断结果
     * @Exception 发生异常
     */
	 public static String dayForWeek(String pTime) throws Exception {
		  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		  Calendar c = Calendar.getInstance();
		  c.setTime(format.parse(pTime));
		  int dayForWeek = 0;
		  if(c.get(Calendar.DAY_OF_WEEK) == 1)
		  {
			  dayForWeek = 7;
		  }
		  else
		  {
			  dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
		  }
		  
		  String wek = "";
		  
		  if(dayForWeek == 1)
		  {
			  wek = "周一";
		  }
		  else if(dayForWeek == 2)
		  {
			  wek = "周二";
		  }
		  else if(dayForWeek == 3)
		  {
			  wek = "周三";
		  }
		  else if(dayForWeek == 4)
		  {
			  wek = "周四";
		  }
		  else if(dayForWeek == 5)
		  {
			  wek = "周五";
		  }
		  else if(dayForWeek == 6)
		  {
			  wek = "周六";
		  }
		  else
		  {
			  wek = "周日";
		  }
		 return wek;
	 }
	 
	 
    
    public static Timestamp strToTimestamp(String str,String formart){
    	if (StringUtils.isBlank(str)) {
            return null;
        }
        Timestamp timestamp = null;
		try {
			timestamp = new Timestamp(new SimpleDateFormat(formart).parse(str).getTime());
		} catch (ParseException e) {
			e.printStackTrace();
		}
        return timestamp;
    }
    
	
	//时间戳
    public static int dateConvertTimeStamp(String time, String formant) throws Exception {
        int re_time = 0;
        SimpleDateFormat sdf = new SimpleDateFormat(formant);
        Date date = sdf.parse(time);
        long l = date.getTime();
        re_time = (int) (l / 1000);
        return re_time;
    }
    
    
    public static Integer dateConvertStamp()throws Exception{
    	return dateConvertTimeStamp(DateToString(new Date(),"yyyy-MM-dd"),"yyyy-MM-dd");
    }
    
    public static String DateToString(Date date, String formatStr){
        DateFormat sdf = new SimpleDateFormat(formatStr);
        String str = sdf.format(date);
        return str;
    }
    
    /**
     * 时间戳转date
     * @param date
     * @param format
     * @return
     * @throws ParseException
     */
    public static Date stampConvertDate(Integer date,String format) throws ParseException{
    	long lt = new Long(date);
    	SimpleDateFormat sdf = new SimpleDateFormat(format);  
    	Date d=sdf.parse(sdf.format(new Date(Long.valueOf(lt+"000"))));
    	return d;
    }
    
    /**
    *转换date 时间 
    *  @author  zhangpp
    *  @Title:  convertDate  
    *    
    *  @param  @param date
    *  @param  @param format
    *  @param  @return        设定文件  
    *  @return  Date        返回类型  
    *  @version  V1.0
    *  @throws
     */
    public static Date convertDate(String date,String format)
    {
    	if(null == date || ("").equals(date))
    	{
    		return null;
    	}
    	
    	try {
    		SimpleDateFormat sdf=new SimpleDateFormat(format);
        	Date ddate =sdf.parse(date);
        	return ddate;
		} catch (Exception e) {
			
			e.printStackTrace();
		}
    	return null;
    }
    
    /* 
     * 将时间戳转换为时间
     */
    public static String stampToDate(int s,String format){
    	SimpleDateFormat sdf = new SimpleDateFormat(format);
 		String date = sdf.format(new Date(s*1000L));
        return date;
    }
    
    public static void main(String[] args) throws Exception{
    	
    	System.out.println(dayForWeek("2017-07-25"));;
	}
}
